home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / net / netware / nwmisc.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-20  |  23.0 KB  |  710 lines

  1. {$X+,B-,V-}
  2.  
  3. UNIT NWMISC;
  4.  
  5. INTERFACE
  6.  
  7. { This unit consists of three parts:
  8.  
  9.   1.It contains some functions that perform startup checks:
  10.  
  11.     IsShellLoaded  ( moved to unit nwBindry )
  12.     IsUserLoggedOn ( moved to unit nwBindry )
  13.     IsV3Supported
  14.  
  15.   2...,some level 0 support functions, used by the other NW units:
  16.  
  17.     UpString
  18.     HexString
  19.     PStrCopy
  20.     ZStrCopy
  21.  
  22.     LoNibble
  23.     HiNibble
  24.     Lswap
  25.     HiLong
  26.     LowLong
  27.     MakeLong
  28.  
  29.     GetNWversion
  30.     NovTimeRec2String
  31.     EncryptPassword
  32.  
  33.   3...and types and constants used by more than one NW unit:
  34.  
  35.     Type
  36.      NovTimeRec
  37.      TconnectionList
  38.      TencryptionKey
  39.  
  40.      TnetworkAdress
  41.      Tnodeadress
  42.      TinternetworkAddress
  43.     Const
  44.      <error numbers>
  45. }
  46.  
  47.  
  48. Type NovTimeRec=record
  49.                 year,month,day,hour,min,sec,DayOfWeek:byte; { 0=sunday }
  50.                 end;
  51.      TconnectionList=array[1..250] of byte;
  52.  
  53.      TencryptionKey=array[0..7] of byte;
  54.  
  55.      TnetworkAddress=array[1..4] of byte; { hi-endian }
  56.      TnodeAddress   =array[1..6] of byte; { Hi-endian }
  57.      TinterNetworkAdress=record
  58.                          net   :TnetworkAddress; {hi-lo}
  59.                          node  :Tnodeaddress;    {hi-lo}
  60.                          socket:word;            {lo-hi}
  61.                          end;
  62.  
  63. Function IsV3Supported:Boolean;
  64.  
  65. Procedure NovTimeRec2String(tim:NovTimeRec;Var DateStr:string);
  66. { Puts the time/date information of a NovTimeRec into a string.
  67.   output format: 'DOW, dd mmm yyyy hh:mm:ss' DOW= day of the week. }
  68.  
  69. {============================level 0 support functions=======================}
  70.  
  71. Procedure UpString(s:string);
  72. { Converts s to upperstring.  Assembler, so it's realy a Var parameter.   }
  73.  
  74. Function HexStr(dw:LongInt;len:byte):string;
  75. { Coverts dw into a hex-string of length len                              }
  76.  
  77. procedure PStrCopy(Var dest:String;source:String;len:byte);
  78. { if length(source)>len
  79.    then Copy len bytes from source to dest.
  80.    else Copy source to dest and fill out with NULLs.
  81.   Length(Dest) will allways be set to len.                          }
  82.  
  83.  
  84. procedure ZStrCopy(dest:String;source:array of byte;len:byte);
  85. { 1. Copies len bytes form an array to a pascal type string.                }
  86. { 2. Trailing NULLs are removed from the string.                            }
  87. { consequently, the length of dest (dest[0]) will allways be <= len.        }
  88.  
  89. Procedure GetNWversion(Var version:word);
  90. { determine the version of software installed on the current file server. }
  91. { see GetFileServerInformation F217/11 for more information }
  92. { Version: MajorVersion * 100 + MinorVersion; e.g. 311 for 3.11 }
  93.  
  94. Procedure EncryptPassword(objId:longint;password:string;Var Ekey:TencryptionKey);
  95. { called by LoginToFileServer (unit nwConn),
  96.   and by VerifyBinderyObjectPassword, ChangeBinderyObjectPassword (nwBindry) }
  97. { Source of the encryption routine: LOGON.PAS by Barry Nance, [1:141/209]
  98.   BYTE March'93 }
  99.  
  100. Function LoNibble(b:Byte):Byte;
  101. { Returns the low nibble of the argument (in low nibble position),
  102.   with high nibble set to 0000                                      }
  103. Function HiNibble(b:Byte):Byte;
  104. { Returns the high nibble of the argument (in low nibble position),
  105.   with high nibble set to 0000                                      }
  106.  
  107.  
  108. Function Lswap(l:Longint):Longint;
  109. { swaps bytes in a longInt; ( reverse byte order )                  }
  110. Inline(
  111.   $5A/        {pop DX       ; low word of long }
  112.   $58/        {pop AX       ; hi word of long  }
  113.  
  114.   $86/$F2/    {xchg dl,dh   ; swap bytes       }
  115.   $86/$E0);   {xchg al,ah   ; swap bytes       }
  116.  
  117. function HiLong(Long : LongInt) : Word;
  118. { This inline directive is similar to Turbo's Hi() function, except }
  119. { it returns the high word of a LongInt                             }
  120. Inline(
  121.   $5A/       {pop      dx    ; low word of long                     }
  122.   $58);      {pop      ax    ; hi word of long                      }
  123.  
  124. function LowLong(Long : LongInt) : Word;
  125. { This inline directive is similar to Turbo's Lo() function, except }
  126. { it returns the Low word of a LongInt                              }
  127. Inline(
  128.   $5A/       {pop      dx    ; low word of long                     }
  129.   $58/       {pop      ax    ; hi word of long                      }
  130.   $89/$D0);  {mov      ax,dx ; return lo word as func. result in Ax }
  131.  
  132. function MakeLong(HiWord,LoWord : Word) : LongInt;
  133. { Takes hi and lo words and makes a longint                         }
  134. Inline(
  135.   $58/    { pop ax ; pop low word into AX                           }
  136.   $5A);   { pop dx ; pop high word into DX                          }
  137.  
  138.  
  139. CONST
  140. {** ERRORS DEFINED BY NWxxx UNITS *******}
  141.  
  142. {** STANDARD ERRORS AS USED BY NETWARE **}
  143.    HARDWARE_FAILURE                = 255;
  144.    INVALID_INITIAL_SEMAPHORE_VALUE = 255; {nwSema}
  145.    INVALID_SEMAPHORE_HANDLE        = 255; {nwSema}
  146.    BAD_PRINTER_ERROR               = 255;
  147.    QUEUE_FULL_ERROR                = 255;
  148.    NO_FILES_FOUND_ERROR            = 255;
  149.    BAD_RECORD_OFFSET               = 255;
  150.    PATH_NOT_LOCATABLE              = 255;
  151.    SOCKET_ALREADY_OPEN             = 255;
  152.    INVALID_DRIVE_NUMBER            = 255; {nwDir}
  153.    NO_RECORD_FOUND                 = 255;
  154.    NO_RESPONSE_FROM_SERVER         = 255;
  155.    REQUEST_NOT_OUTSTANDING         = 255;
  156.    NO_SUCH_OBJECT_OR_BAD_PASSWORD  = 255;
  157.    CLOSE_FCB_ERROR                 = 255;
  158.    FILE_EXTENSION_ERROR            = 255;
  159.    FILE_NAME_ERROR                 = 255;
  160.    IO_BOUND_ERROR                  = 255;
  161.    SPX_IS_INSTALLED                = 255; {nwIpx}
  162.    SPX_SOCKET_NOT_OPENED           = 255; {nwIpx}
  163.    EXPLICIT_TRANSACTION_ACTIVE     = 255; {nwTTS}
  164.    NO_EXPLICIT_TRANSACTION_ACTIVE  = 255; {nwTTS}
  165.    TRANSACTION_NOT_YET_WRITTEN     = 255; {nwTTS}
  166.    NO_MORE_MATCHING_FILES          = 255; {nwTTS}
  167.    BINDERY_FAILURE                 = 255;
  168.    OPEN_FILES                      = 255;  {3.x}
  169.    PRINT_JOB_ALREADY_QUEUED        = 255;  {3.x}
  170.    PRINT_JOB_ALREADY_SET           = 255;  {3.x}
  171.    SUPERVISOR_HAS_DISABLED_LOGIN   = 254; {nwConn}
  172.    TIMEOUT_FAILURE                 = 254;
  173.    BINDERY_LOCKED                  = 254; {nwBindry}
  174.    SERVER_BINDERY_LOCKED           = 254;
  175.    INVALID_SEMAPHORE_NAME_LENGTH   = 254; {nwSema}
  176.    PACKET_NOT_DELIVERABLE          = 254;
  177.    SOCKET_TABLE_FULL               = 254;
  178.    DIRECTORY_LOCKED                = 254;
  179.    SPOOL_DIRECTORY_ERROR           = 254;
  180.    IMPLICIT_TRANSACTION_ACTIVE     = 254; {nwTTS}
  181.    TRANSACTION_ENDS_RECORD_LOCK    = 254; {nwTTS}
  182.    IO_FAILURE                      = 254;  {3.x}
  183.    UNKNOWN_REQUEST                 = 253;
  184.    INVALID_PACKET_LENGTH           = 253;
  185.    FIELD_ALREADY_LOCKED            = 253;
  186.    BAD_STATION_NUMBER              = 253;
  187.    SPX_MALFORMED_PACKET            = 253;
  188.    SPX_PACKET_OVERFLOW             = 253;
  189.    TTS_DISABLED                    = 253;
  190.    NO_SUCH_OBJECT                  = 252;
  191.    UNKNOWN_FILE_SERVER             = 252;
  192.    INTERNET_PACKET_REQT_CANCELED   = 252;
  193.    MESSAGE_QUEUE_FULL              = 252; {nwMess}
  194.    SPX_LISTEN_CANCELED             = 252;
  195.    NO_SUCH_PROPERTY                = 251;
  196.    INVALID_PARAMETERS              = 251;
  197.    {UNKNOWN_REQUEST                 = 251; ?double see 253}
  198.    NO_MORE_SERVER_SLOTS            = 250;
  199.    TEMP_REMAP_ERROR                = 250;
  200.    NO_PROPERTY_READ_PRIVILEGE      = 249;
  201.    NO_FREE_CONNECTION_SLOTS        = 249;
  202.    NO_PROPERTY_WRITE_PRIVILEGE     = 248;
  203.    ALREADY_ATTACHED_TO_SERVER      = 248;
  204.    NOT_ATTACHED_TO_SERVER          = 248;
  205.    NO_PROPERTY_CREATE_PRIVILEGE    = 247;
  206.    TARGET_DRIVE_NOT_LOCAL          = 247;
  207.    NO_PROPERTY_DELETE_PRIVILEGE    = 246;
  208.    NOT_SAME_LOCAL_DRIVE            = 246;
  209.    NO_OBJECT_CREATE_PRIVILEGE      = 245;
  210.    NO_OBJECT_DELETE_PRIVILEGE      = 244;
  211.    NO_OBJECT_RENAME_PRIVILEGE      = 243;
  212.    NO_OBJECT_READ_PRIVILEGE        = 242;
  213.    INVALID_BINDERY_SECURITY        = 241;
  214.    WILD_CARD_NOT_ALLOWED           = 240;
  215.    IPX_NOT_INSTALLED               = 240; {nwIpx}
  216.    INVALID_NAME                    = 239;
  217.    SPX_CONNECTION_TABLE_FULL       = 239;
  218.    OBJECT_ALREADY_EXISTS           = 238;
  219.    SPX_INVALID_CONNECTION          = 238;
  220.    PROPERTY_ALREADY_EXISTS         = 237;
  221.    SPX_NO_ANSWER_FROM_TARGET       = 237;
  222.    SPX_CONNECTION_FAILED           = 237;
  223.    SPX_CONNECTION_TERMINATED       = 237;
  224.    NO_SUCH_SEGMENT                 = 236;
  225.    SPX_TERMINATED_POORLY           = 236;
  226.    NOT_GROUP_PROPERTY              = 235;
  227.    NO_SUCH_MEMBER                  = 234;
  228.    MEMBER_ALREADY_EXISTS           = 233;
  229.    NOT_ITEM_PROPERTY               = 232;
  230.    WRITE_PROPERTY_TO_GROUP         = 232;
  231.    PASSWORD_HAS_EXPIRED            = 223;
  232.    PASSWORD_HAS_EXPIRED_NO_GRACE   = 222;
  233.    ACCOUNT_DISABLED                = 220;
  234.    UNAUTHORIZED_LOGIN_STATION      = 219;
  235.    MAX_Q_SERVERS                   = 219;
  236.    UNAUTHORIZED_LOGIN_TIME         = 218;
  237.    Q_HALTED                        = 218;
  238.    LOGIN_DENIED_NO_CONNECTION      = 217;
  239.    STN_NOT_SERVER                  = 217;
  240.    PASSWORD_TOO_SHORT              = 216;
  241.    Q_NOT_ACTIVE                    = 216;
  242.    PASSWORD_NOT_UNIQUE             = 215;
  243.    Q_SERVICING                     = 215;
  244.    NO_JOB_RIGHTS                   = 214;
  245.    NO_Q_JOB                        = 213;
  246.    Q_FULL                          = 212;
  247.    NO_Q_RIGHTS                     = 211;
  248.    NO_Q_SERVER                     = 210;
  249.    NO_QUEUE                        = 209;
  250.    Q_ERROR                         = 208;
  251.    NOT_CONSOLE_OPERATOR            = 198;
  252.    INTRUDER_DETECTION_LOCK         = 197;
  253.    ACCOUNT_TOO_MANY_HOLDS          = 195;
  254.    CREDIT_LIMIT_EXCEEDED           = 194;
  255.    NO_ACCOUNT_BALANCE              = 193;
  256.    NO_ACCOUNT_PRIVILEGES           = 192;
  257.    READ_FILE_WITH_RECORD_LOCKED    = 162;
  258.    DIRECTORY_IO_ERROR              = 161;
  259.    DIRECTORY_NOT_EMPTY             = 160;
  260.    DIRECTORY_ACTIVE                = 159;
  261.    INVALID_FILENAME                = 158;
  262.    NO_MORE_DIRECTORY_HANDLES       = 157;
  263.    NO_MORE_TRUSTEES                = 156;
  264.    INVALID_PATH                    = 156;
  265.    BAD_DIRECTORY_HANDLE            = 155;
  266.    RENAMING_ACROSS_VOLUMES         = 154;
  267.    DIRECTORY_FULL                  = 153;
  268.    VOLUME_DOES_NOT_EXIST           = 152;
  269.    NO_DISK_SPACE_FOR_SPOOL_FILE    = 151;
  270.    SERVER_OUT_OF_MEMORY            = 150;
  271.    OUT_OF_DYNAMIC_WORKSPACE        = 150;
  272.    FILE_DETACHED                   = 149;
  273.    NO_WRITE_PRIVILEGES             = 148;
  274.    READ_ONLY                       = 148;
  275.    NO_READ_PRIVILEGES              = 147;
  276.    NO_FILES_RENAMED_NAME_EXISTS    = 146;
  277.    SOME_FILES_RENAMED_NAME_EXISTS  = 145;
  278.    NO_FILES_AFFECTED_READ_ONLY     = 144;
  279.    SOME_FILES_AFFECTED_READ_ONLY   = 143;
  280.    NO_FILES_AFFECTED_IN_USE        = 142;
  281.    SOME_FILES_AFFECTED_IN_USE      = 141;
  282.    NO_MODIFY_PRIVILEGES            = 140;
  283.    NO_RENAME_PRIVILEGES            = 139;
  284.    NO_DELETE_PRIVILEGES            = 138;
  285.    NO_SEARCH_PRIVILEGES            = 137;
  286.    INVALID_FILE_HANDLE             = 136;
  287.    WILD_CARDS_IN_CREATE_FILENAME   = 135;
  288.    CREATE_FILE_EXISTS_READ_ONLY    = 134;
  289.    NO_CREATE_DELETE_PRIVILEGES     = 133;
  290.    NO_CREATE_PRIVILEGES            = 132;
  291.    IO_ERROR_NETWORK_DISK           = 131;
  292.    NO_OPEN_PRIVILEGES              = 130;
  293.    NO_MORE_FILE_HANDLES            = 129;
  294.    FILE_IN_USE_ERROR               = 128;
  295.    DOS_LOCK_VIOLATION              = 33;
  296.    DOS_SHARING_VIOLATION           = 32;
  297.    DOS_NO_MORE_FILES               = 31;
  298.    DOS_NOT_SAME_DEVICE             = 30;
  299.    DOS_ATTEMT_TO_DEL_CURRENT_DIR   = 16;
  300.    DOS_INVALID_DRIVE               = 15;
  301.    DOS_INVALID_DATA                = 13;
  302.    DOS_INVALID_ACCESS_CODE         = 12;
  303.    DOS_INVALID_FORMAT              = 11;
  304.    DOS_INVALID_ENVIRONMENT         = 10;
  305.    DOS_INVALID_MEMORY_BLOCK_ADDR   = 9;
  306.    DOS_INSUFFICIENT_MEMORY         = 8;
  307.    DOS_MEMORY_BLOCKS_DESTROYED     = 7;
  308.    DOS_INVALID_FILE_HANDLE         = 6;
  309.    DOS_ACCESS_DENIED               = 5;
  310.    DOS_TOO_MANY_OPEN_FILES         = 4;
  311.    DOS_PATH_NOT_FOUND              = 3;
  312.    DOS_FILE_NOT_FOUND              = 2;
  313.    TTS_AVAILABLE                   = 1;
  314.    SERVER_IN_USE                   = 1;
  315.    SEMAPHORE_OVERFLOW              = 1;
  316.    DOS_INVALID_FUNCTION_NUMBER     = 1;
  317.    TTS_NOT_AVAILABLE               = 1;
  318.    SERVER_NOT_IN_USE               = 1;
  319.  
  320. IMPLEMENTATION{=============================================================}
  321.  
  322.  
  323. Uses dos;
  324.  
  325.  
  326. Procedure EncryptPassword(objId:longint;password:string;Var Ekey:TencryptionKey);
  327. { called by LoginTo3Xserver }
  328. { Source of the encryption routine: LOGON.PAS by Barry Nance, [1:141/209]
  329.   BYTE March'93 }
  330. TYPE
  331.   Buf32 = ARRAY [0..31] OF Byte;
  332.   Buf16 = ARRAY [0..15] OF Byte;
  333.   Buf4  = ARRAY [0..3]  OF Byte;
  334.  
  335. CONST
  336.   EncryptTable : ARRAY [Byte] OF Byte =
  337. ($7,$8,$0,$8,$6,$4,$E,$4,$5,$C,$1,$7,$B,$F,$A,$8,
  338.  $F,$8,$C,$C,$9,$4,$1,$E,$4,$6,$2,$4,$0,$A,$B,$9,
  339.  $2,$F,$B,$1,$D,$2,$1,$9,$5,$E,$7,$0,$0,$2,$6,$6,
  340.  $0,$7,$3,$8,$2,$9,$3,$F,$7,$F,$C,$F,$6,$4,$A,$0,
  341.  $2,$3,$A,$B,$D,$8,$3,$A,$1,$7,$C,$F,$1,$8,$9,$D,
  342.  $9,$1,$9,$4,$E,$4,$C,$5,$5,$C,$8,$B,$2,$3,$9,$E,
  343.  $7,$7,$6,$9,$E,$F,$C,$8,$D,$1,$A,$6,$E,$D,$0,$7,
  344.  $7,$A,$0,$1,$F,$5,$4,$B,$7,$B,$E,$C,$9,$5,$D,$1,
  345.  $B,$D,$1,$3,$5,$D,$E,$6,$3,$0,$B,$B,$F,$3,$6,$4,
  346.  $9,$D,$A,$3,$1,$4,$9,$4,$8,$3,$B,$E,$5,$0,$5,$2,
  347.  $C,$B,$D,$5,$D,$5,$D,$2,$D,$9,$A,$C,$A,$0,$B,$3,
  348.  $5,$3,$6,$9,$5,$1,$E,$E,$0,$E,$8,$2,$D,$2,$2,$0,
  349.  $4,$F,$8,$5,$9,$6,$8,$6,$B,$A,$B,$F,$0,$7,$2,$8,
  350.  $C,$7,$3,$A,$1,$4,$2,$5,$F,$7,$A,$C,$E,$5,$9,$3,
  351.  $E,$7,$1,$2,$E,$1,$F,$4,$A,$6,$C,$6,$F,$4,$3,$0,
  352.  $C,$0,$3,$6,$F,$8,$7,$B,$2,$D,$C,$6,$A,$A,$8,$D);
  353.  
  354.   EncryptKeys : Buf32 =
  355. ($48,$93,$46,$67,$98,$3D,$E6,$8D,$B7,$10,$7A,$26,$5A,$B9,$B1,$35,
  356.  $6B,$0F,$D5,$70,$AE,$FB,$AD,$11,$F4,$47,$DC,$A7,$EC,$CF,$50,$C0);
  357.  
  358. Var buf:buf32;
  359.     TobjId:Longint;
  360.     Tpassword:string;
  361.  
  362.    PROCEDURE Shuffle1(VAR temp : Buf32; VAR target);
  363.    VAR _target  :  Buf16 ABSOLUTE target;
  364.        b4 :  Word;
  365.        b3 :  Byte;
  366.        d, k, i : Word;
  367.    Begin
  368.  
  369.    {** Step 4: .. }
  370.    b4 := 0;
  371.    FOR k := 0 TO 1
  372.     DO Begin
  373.        FOR i := 0 TO 31
  374.         DO Begin
  375.            b3 := Lo( Lo(temp[i] + b4) XOR
  376.                  Lo(temp[(i + b4) AND 31] - EncryptKeys[i]));
  377.            b4 := b4 + b3;
  378.            temp[i] := b3;
  379.            End;
  380.        End;
  381.  
  382.    {*** Step 5:... }
  383.  
  384.    FOR i := 0 TO 15
  385.     DO _Target[i] := EncryptTable[temp[i Shl 1]] OR
  386.                     (EncryptTable[temp[i Shl 1 +1]] Shl 4);
  387.    End;
  388.  
  389.  
  390.    PROCEDURE Shuffle(VAR ShuffleKey, buf; buflen : Word; VAR target);
  391.    { id, password[1.. ],length(passw), OUT: buf }
  392.    VAR locShuffleKey : Buf4 ABSOLUTE ShuffleKey;
  393.        localBuf : ARRAY [0..127] OF Byte ABSOLUTE buf;
  394.        BufBytesUsed : Word;
  395.        temp : Buf32;
  396.        t, IndexOfBufBytes : Word;
  397.    Begin
  398.    { strip trailing NULLs of the to-be-encoded buf,
  399.      last element of buf must be a NULL ? }
  400.    While (buflen > 0) AND (localBuf[buflen-1] = 0)
  401.     DO buflen := buflen - 1;
  402.    { clear output of 1st shuffle }
  403.    FillChar(temp, SizeOf(temp), #0);
  404.  
  405.    {*** 1ST Step: XOR folding of first (32*(buflen DIV 32)) bytes. }
  406.  
  407.    { temp= buf[0..31] XOR buf[32..63] XOR buf[64..95] XOR etc.. }
  408.  
  409.    { IndexOfBufBytes is een 32-voud, lengte password was: IndexOfBufBytes + buflen }
  410.    { temp gevuld met XOR folding van de eerste IndexOfBufBytes bytes. }
  411.    IndexOfBufBytes := 0;
  412.    WHILE buflen >= 32
  413.     DO Begin
  414.        FOR t := 0 TO 31
  415.         DO Begin
  416.            temp[t] := temp[t] XOR localBuf[IndexOfBufBytes];
  417.            IndexOfBufBytes := IndexOfBufBytes + 1;
  418.            End;
  419.        buflen := buflen - 32;
  420.        End;
  421.  
  422.    {*** 2ND step: repetitive XOR folding with (remainder of) password
  423.  
  424.      password='hello', (BufBytesUsed=0)
  425.      or password='12345678901234567890123456789012hello' (BufBytesUsed=32)
  426.      of which the first 32 bytes were used in the 1st encryption step.
  427.  
  428.      temp=temp XOR [hellohellohellohellohellohellohe];
  429.     }
  430.    BufBytesUsed:=IndexOfBufBytes;
  431.    IF buflen > 0
  432.     Then Begin
  433.          FOR t := 0 TO 31
  434.           DO Begin
  435.              IF IndexOfBufBytes + buflen = BufBytesUsed
  436.               Then Begin
  437.                    BufBytesUsed := IndexOfBufBytes;
  438.                    temp[t] := temp[t] XOR EncryptKeys[t];
  439.                    End
  440.               Else Begin
  441.                    temp[t] := temp[t] XOR localBuf[BufBytesUsed];
  442.                    BufBytesUsed := BufBytesUsed + 1;
  443.                    End;
  444.              End;
  445.          End;
  446.    {*** 3RD step: XOR-ing with shuffleKey (bytes of a longint)}
  447.  
  448.    FOR t := 0 TO 31 DO temp[t] := temp[t] XOR locShuffleKey[t AND 3];
  449.  
  450.    {*** 4&5 TH Step: see Shuffle1 }
  451.  
  452.    Shuffle1(temp, target);
  453.    End;
  454.  
  455.  
  456.     PROCEDURE Encrypt(VAR key, buf, EncrPassword);
  457.   { The encryptionKey 'key' is encrypted with the aid of
  458.     the encrypted login name/id within 'buf'.
  459.     Result: the Password to login with (of type TencryptionKey). }
  460.   VAR _Key : TencryptionKey  ABSOLUTE Key;
  461.       _EncrKey : TencryptionKey  ABSOLUTE EncrPassword;
  462.       _LocalBuf : Buf32;
  463.       i: Byte;
  464.   Begin
  465.     Shuffle(_Key[0], buf, 16, _LocalBuf[0]);
  466.     Shuffle(_Key[4], buf, 16, _LocalBuf[16]);
  467.     FOR i := 0 TO 15 DO _LocalBuf[i] := _LocalBuf[i] XOR _LocalBuf[31-i];
  468.     FOR i := 0 TO 7 DO _EncrKey[i] := _LocalBuf[i] XOR _LocalBuf[15-i];
  469.   End;
  470.  
  471. begin
  472. TobjId:=objId;
  473. Tpassword:=password;
  474. Shuffle(TObjId,Tpassword[1],length(password),buf);
  475. Encrypt(Ekey,buf,Ekey);
  476. end;
  477.  
  478.  
  479. Procedure UpString(s : String); Assembler;
  480. { fast upcasestring by Bob Swart }
  481. ASM
  482.         PUSH   DS
  483.         LDS    SI, s
  484.         LES    DI, s
  485.         CLD
  486.         XOR    AH, AH
  487.         LODSB
  488.         STOSB
  489.         XCHG   AX, CX           { empty string? }
  490.         JCXZ   @2
  491. @1:     LODSB
  492.         SUB    AL, 'a'
  493.         CMP    AL, 'z'-'a'+1
  494.         SBB    AH, AH
  495.         AND    AH, 'a'-'A'
  496.         SUB    AL, AH
  497.         ADD    AL, 'a'
  498.         STOSB
  499.         LOOP   @1
  500. @2:     POP    DS
  501. end;
  502.  
  503.  
  504. {$IFDEF newcalls}
  505.  
  506. procedure PStrCopy(Var dest:String;source:String;len:byte);
  507. { if length(source)>len
  508.    then Copy len bytes from source to dest.
  509.    else Copy source to dest and fill out with NULLs.
  510.   Length(Dest) will allways be set to len.                          }
  511. begin
  512. FillChar(dest[1],len,#0);
  513. move(source[1],dest[1],ord(source[0]));
  514. dest[0]:=chr(len);
  515. end;
  516.  
  517. procedure ZStrCopy(Var dest:String;source:array of byte;len:byte);
  518. { 1. Copies len bytes from an array to a pascal type string.                }
  519. { 2. Trailing NULLs are removed from the string.                            }
  520. { consequently, the length of dest (dest[0]) will allways be <= len.         }
  521. begin
  522. Move(source,dest[1],len);
  523. while (dest[len]=#0) and (len>0) do dec(len);
  524. dest[0]:=chr(len);
  525. end;
  526.  
  527. {$ENDIF}
  528.  
  529.  
  530. procedure PStrCopy(Var dest:String;source:String;len:byte);
  531. Var w:byte;
  532. begin
  533. w:=1;
  534. dest[0]:=chr(len);
  535. While w<=ord(source[0])
  536.  do begin
  537.     dest[w]:=source[w];
  538.     inc(w)
  539.     end;
  540. While w<=len
  541.  do begin
  542.     dest[w]:=#0;
  543.     inc(w)
  544.     end;
  545. end;
  546.  
  547. procedure ZStrCopy(dest:String;source:array of byte;len:byte); assembler;
  548. { 1. Copies len bytes from an array to a pascal type string.                }
  549. { 2. Trailing NULLs are removed from the string.                            }
  550. { consequently, the length of det (dest[0]) will allways be <= len.         }
  551. asm
  552. mov dx,ds        { fast save current DS }
  553. les di,dest
  554. lds si,source
  555.  
  556. xor ah,ah       { ah:=0 }
  557. mov al,len
  558. mov es:[di],al  { dest[0]:=len }
  559. inc di          { es:di => dest[1] ; ds:si => source[0] }
  560.  
  561. mov cx,ax
  562. cld
  563. rep movsb
  564.  
  565. { begin DeleteTrailingNulls }
  566. les di,dest
  567. xor bh,bh
  568. mov bl,len
  569. @rep:
  570. mov al,es: [di] [bx]
  571. and al,al
  572. jne @cont
  573.  
  574. dec bl
  575. jne @rep
  576.  
  577. @cont:
  578. mov es:[di],bl   { set length of dest string }
  579. { end DeleteTrailingNulls }
  580.  
  581. mov ds,dx       { restore DS }
  582. end;
  583.  
  584. Procedure NovTimeRec2String(tim:NovTimeRec;Var DateStr:string);
  585. CONST day:array[0..6] of string[3]
  586.           =('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  587.       Month:array[1..12] of string[3]
  588.           =('Jan','Feb','Mar','Apr','May','Jun',
  589.             'Jul','Aug','Sep','Oct','Nov','Dec');
  590. Type string4=string[4];
  591. Var  sday,syear,shour,smin,ssec:string4;
  592.   Procedure zstr(n:byte;Var s:string4);
  593.   begin
  594.   str(n,s);
  595.   if s[0]=#1 then s:='0'+s;
  596.   end;
  597. begin
  598. if (tim.month>12) or (tim.month<1)
  599.    or (tim.day<1) or (tim.day>31)
  600.    or (tim.hour>23) or (tim.min>59) or (tim.sec>59)
  601.  then DateStr:='<invalid date & time>    '
  602.  else begin
  603.       zstr(tim.day,sday);
  604.       if sday[1]='0' then sday[1]:=' ';
  605.       if tim.year<80 then str(tim.year+2000,syear)
  606.                      else str(tim.year+1900,syear);
  607.       zstr(tim.hour,shour);
  608.       zstr(tim.min,smin);
  609.       zstr(tim.sec,ssec);
  610.       DateStr:=day[tim.DayOfWeek]+', '+
  611.                sday+' '+Month[tim.month]+' '+syear+' '+
  612.                shour+':'+smin+':'+ssec;
  613.       end;
  614. end;
  615.  
  616. Function LoNibble(b:Byte):Byte; assembler;
  617. asm
  618. mov al,b
  619. and al,$0F
  620. end;
  621.  
  622. Function HiNibble(b:Byte):Byte; assembler;
  623. asm
  624. mov ah,$00
  625. mov al,b
  626. shr ax,1
  627. shr ax,1
  628. shr ax,1
  629. shr ax,1
  630. end;
  631.  
  632. Function HexStr(dw:LongInt;len:byte):string;
  633. CONST n:array[0..15] of char
  634.       =('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  635. Var t:integer;
  636.     ldw:LongInt;
  637.     res:string;
  638. begin
  639. res:='';
  640. for t:=1 to len
  641. do begin
  642.    ldw:=dw AND $0000000F;
  643.    res:=n[ldw]+res;
  644.    dw:=dw SHR 4;
  645.    end;
  646. HexStr:=res;
  647. end;
  648.  
  649.  
  650. Procedure GetNWversion(Var version:word);
  651. { determine the version of the software installed on the current file server. }
  652. { see GetServerInformation F217/11 in the nwServ unit for more information }
  653.  
  654. { version : word; contains the versionnumber of the fileserver we're
  655.             currently connected to. Used by primary functions to
  656.             determine what type of calls to use to perform a certain function.
  657.  
  658.             format: (majorVersion*100)+minorVersion
  659.                     e.g. 311 for 3.11
  660.             Range: 100 (advanced netware 1.00) and upwards    }
  661. { note: you don't have to be logged in to call this function. }
  662. Var  Reg            : Registers;
  663.      RequestBuffer  : Record
  664.                       PacketLength : Word;
  665.                       FunctionVal  : Byte;
  666.                       End;
  667.      ReplyBuffer:array[1..$80] of byte;
  668.      ReplyLength:word ABSOLUTE ReplyBuffer; { not needed for F2 call }
  669. Begin
  670. With RequestBuffer
  671. Do Begin
  672.    PacketLength := 1; FunctionVal := $11;
  673.    End;
  674. With reg
  675.  do begin
  676.     ax := $f217;
  677.     ds:=SEG(requestBuffer);   si := OFs(requestBuffer);
  678.     cx:=sizeOf(requestBuffer);
  679.     es:=SEG(replyBuffer); di := OFs(replyBuffer);
  680.     dx:=sizeOf(replyBuffer);
  681.     MsDos(reg);
  682.     end;
  683. If reg.AL=0
  684.  then version:=(ReplyBuffer[49]*100)+ReplyBuffer[50]
  685.  else begin { If F217/11 failed, try old E3../11 call }
  686.       ReplyLength := $80;
  687.       With Reg
  688.       Do Begin
  689.          Ah := $e3;
  690.          Ds := Seg(RequestBuffer); Si := Ofs(RequestBuffer);
  691.          Es := Seg(ReplyBuffer);   Di := Ofs(ReplyBuffer);
  692.          End;
  693.       MsDos(Reg);
  694.       if reg.AL<>0
  695.        then version:=$00
  696.        else version:=(ReplyBuffer[51]*100)+ReplyBuffer[52];
  697.       end;
  698. End;
  699.  
  700.  
  701. Function IsV3Supported:boolean;
  702. Var version:word;
  703. begin
  704. GetNWversion(version);
  705. IsV3Supported:=(version>=300);
  706. end;
  707.  
  708.  
  709. END.
  710.